﻿<div ng-controller="Approval_ManageItemsC">
    <div class="modal fade" id="dlg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form name="myform1">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">添加{{typename2}}流程节点</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label>序号（越小越靠前）（必填）</label>
                            <input type="number" min="0" required class="form-control" ng-model="maindata.Index">
                        </div>
                        <div class="form-group">
                            <label>执行条件</label>
                            <input type="text" class="form-control" ng-model="maindata.ExeExpression">
                        </div>
                        <div class="form-group">
                            <label>审批人表达式</label>
                            <input type="text" class="form-control" ng-model="maindata.ApproverExpression">
                        </div>
                        <div class="form-group">
                            <label>审批人名称（必填）</label>
                            <input disabled type="text" required class="form-control" ng-model="maindata.ApproverName">
                            <div class="input-group ">
                                <input class="selectFind form-control" type="search" ng-model="searchTxt" placeholder="查找">
                                <span class="glyphicon glyphicon-remove input-group-addon" ng-click="empty()"></span>
                            </div>
                            <div class="selectShow" style="width: 100%; height: 100px; border: 1px solid #CCCCCC; overflow: auto;">
                                <div style="cursor: pointer;" class="form-control" ng-click="selectEmp(x,2)" ng-repeat=" x in userdata|filter:{Name : searchTxt}">{{x.Name}}</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>备注</label>
                            <input type="text" class="form-control" ng-model="maindata.Remark">
                        </div>
                        <div class="form-group">
                            <label>名称</label>
                            <input type="text" class="form-control" ng-model="maindata.Name">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success" ng-disabled="myform1.$invalid" ng-click="okchange()">添加</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="modal fade" id="dlg2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form name="myform2">
                    <div class="modal-header">
                        <button ng-click="abolish()" type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel2">修改{{typename2}}流程节点</h4>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label>序号（越小越靠前）（必填）</label>
                            <input type="number" min="0" required class="form-control" ng-model="newmaindata.Index">
                        </div>
                        <div class="form-group">
                            <label>执行条件</label>
                            <input type="text" class="form-control" ng-model="newmaindata.ExeExpression">
                        </div>
                        <div class="form-group">
                            <label>审批人表达式</label>
                            <input type="text" class="form-control" ng-model="newmaindata.ApproverExpression">
                        </div>
                        <div class="form-group">
                            <label>审批人名称（必填）</label>
                            <input disabled type="text" required class="form-control" ng-model="newmaindata.ApproverName">
                            <div class="input-group ">
                                <input class="selectFind form-control" type="search" ng-model="searchTxt" placeholder="查找">
                                <span class="glyphicon glyphicon-remove input-group-addon" ng-click="empty()"></span>
                            </div>
                            <div class="selectShow" style="width: 100%; height: 100px; border: 1px solid #CCCCCC; overflow: auto;">
                                <div style="cursor: pointer;" class="form-control" ng-click="selectEmp(x,1)" ng-repeat=" x in userdata|filter:{Name : searchTxt}">{{x.Name}}</div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>备注</label>
                            <input type="text" class="form-control" ng-model="newmaindata.Remark">
                        </div>
                        <div class="form-group">
                            <label>名称</label>
                            <input type="text" class="form-control" ng-model="newmaindata.Name">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success" ng-disabled="myform2.$invalid" ng-click="amend()">确定</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="abolish()">关闭</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">审批流程管理列表</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading text-right">
                <!--<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">-->
                <button class="btn btn-sm btn-default" data-toggle="modal" data-target="#dlg">
                    <i class="fa fa-plus text"></i>
                    <span class="text">添加</span>
                </button>
                <button type="button" class="btn btn-default" ng-click="$state.go('app.Approval_Manage')">返回</button>
                <!--</div>-->
                <!--<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 input-group">-->
                <!--<input type="text" class="form-control" placeholder="按名称查找" ng-model="findname">-->
                <!--<span class="input-group-btn">-->
                <!--<button class="btn btn-default" type="button" ng-click="find()">查找</button>-->
                <!--</span>-->
                <!--</div>-->
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light">
                    <thead>
                        <tr>
                            <th style="text-align: center;">流程名称</th>
                            <th style="text-align: center;">序号</th>
                            <th style="text-align: center;">执行条件</th>
                            <th style="text-align: center;">审批人表达式</th>
                            <th style="text-align: center;">审批人名称</th>
                            <th style="text-align: center;">备注</th>
                            <th style="text-align: center;">操作</th>

                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="item in listData">
                            <td style="width: 15%">{{item.TypeName}}</td>
                            <td style="width: 10%">{{item.Index}}</td>
                            <td style="width: 15%">{{item.ExeExpression}}</td>
                            <td style="width: 15%">{{item.ApproverExpression}}</td>
                            <td style="width: 15%">{{item.ApproverName}}</td>
                            <td style="width: 15%">{{item.Remark}}</td>
                            <td style="width: 15%">
                                <button class="btn btn-sm btn-default" ng-click="edit(item)" data-toggle="modal" data-target="#dlg2">
                                    <span class="text">编辑</span>
                                </button>
                                <button class="btn btn-sm btn-danger" ng-click="remove(item)">
                                    <span class="text">删除</span>
                                </button>
                            </td>

                        </tr>
                    </tbody>
                </table>
                <div class="panel-heading"  >
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    angular.module('app')//非标优惠
.controller("Approval_ManageItemsC", function ($scope, $state, $http, $stateParams) {
    $scope.typename2 = $stateParams.typeName;
    $scope.maindata = {};
    $http({
        url: "/api/Approval/ManageItems",
        method: "GET",
        params: {typeName:$stateParams.typeName}
        })
     .then(function (res) {
         $scope.listData = res.data;
         console.log($scope.listData)
     })
     .then(function (error) {
         if (error) {
             alert("数据获取失败");
         }
     });
    //获取人员
    $http({
        url: "../api/Employee/List?name=&page=1&rows=9999",
        method: "GET"
    })
            .then(function(res) {
                $scope.userdata = res.data.Data;
            })
            .then(function(error) {
                if (error) {
                    console.log("error");
                }
            });

    $scope.selectEmp= function(emp,type) {
        console.log(emp);
        if (type == 1){
            $scope.newmaindata.Approver = emp;
            $scope.newmaindata.ApproverName = emp.Name;
        }else if(type == 2){
            $scope.maindata.Approver = emp;
            $scope.maindata.ApproverName = emp.Name;
        }
    };
    $scope.abolish = function(){
        $state.go('app.Approval_ManageItems', { typeName: $stateParams.typeName })
    };
    $scope.empty = function(){
        $scope.searchTxt = "";
    };
    $scope.okchange = function(){
        $scope.maindata.typeName = $stateParams.typeName;
        console.log($scope.maindata);
        $http.post('../api/SequenceApproval/AddItem', $scope.maindata)
                .success(function (res) {
                    console.log(res);
                    if (res.State <= 0) {
                        alert(res.Msg);
                    } else {
                        alert("添加成功");
                        $('#dlg').modal("hide");
                        $state.go('app.Approval_ManageItems', { typeName: $stateParams.typeName })
                    }
                });
    };
    $scope.edit = function(item){

        $scope.newmaindata = item;
        console.log($scope.newmaindata);
    };
    $scope.amend = function(){
        $scope.newmaindata.typeName = $stateParams.typeName;
        console.log($scope.newmaindata);
        $http.post('../api/SequenceApproval/EditItem', $scope.newmaindata)
                .success(function (res) {
                    console.log(res);
                    if (res.State <= 0) {
                        alert(res.Msg);
                    } else {
                        alert("修改成功");
                        $('#dlg2').modal("hide");
                        $state.go('app.Approval_ManageItems', { typeName: $stateParams.typeName })
                    }
                });
    };
    $scope.remove = function (item) {
        console.log(item);
        if (confirm("确定删除")) {
            $http({
                url: "../api/SequenceApproval/DeleteItem?itemId=" + item.Id,
                method: "DELETE"
            })
                    .then(function (res) {
                        alert("删除成功");
                        $state.go('app.Approval_ManageItems', { typeName: $stateParams.typeName })
                    })
                    .then(function (error) {
                        if (error) {
                            console.log("error");
                        }
                    });
        } else {
            console.log("操作取消");
        }
    }
    })

</script>

